﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Omes.Model;
using Omes.Services;

namespace FashionMural.Admin
{
    public partial class ContentManageChildMenuEdit : System.Web.UI.Page
    {
        protected Omes.Model.Page CurrentPage { get; set; }

        protected List<Omes.Model.PageType> CurentPagePageTypes { get; set; }

        protected int SigleEditFlag = -1;//-1is dont exit,0 is exit;

        protected int NewsEditFlag = -1;//-1 is dont exit,0 is exit;

        protected int ImageEditFlag = -1;//-1 is dont exit,0 is exit;

        protected int OutLinkFlag = -1;//is same to up;

        protected void Page_Load(object sender, EventArgs e)
        {
            int nodeid = Convert.ToInt32(Request.QueryString["nodeid"]);
            try
            {
                //get currentpage
                DbServer bd = new DbServer();
                CurrentPage = bd.GetPage(nodeid);
                if (CurrentPage == null || CurrentPage.Id == 0)
                {
                    List<Omes.Model.Page> pages = bd.GetAllPages();
                    CurrentPage = pages.Last();
                }
                //show left bar in browse
                //this.ShowBarMenu();
                ////get currentpage's pagetype
                //CurentPagePageTypes = bd.GetPageTypes(CurrentPage.Id);
                ////set value to edit flag
                //SigleEditFlag = CurentPagePageTypes.Where(t => (t.PageTypeName.Contains("单页图文"))).FirstOrDefault() ==
                //                null
                //                    ? -1
                //                    : 0;
                //NewsEditFlag = CurentPagePageTypes.Where(t => (t.PageTypeName.Contains("新闻"))).FirstOrDefault() == null
                //                   ? -1
                //                   : 0;
                //ImageEditFlag = CurentPagePageTypes.Where(t => (t.PageTypeName.Contains("图片列表"))).FirstOrDefault() ==
                //                null
                //                    ? -1
                //                    : 0;
                //OutLinkFlag = CurentPagePageTypes.Where(t => (t.PageTypeName.Contains("外部链接"))).FirstOrDefault() == null
                //                  ? -1
                //                  : 0;


            }
            catch (Exception)
            {

                throw;
            }
            if (!Page.IsPostBack)
            {

            }
        }


        //protected void ShowBarMenu()
        //{
        //    Omes.Services.DbServer db = new DbServer();
        //    List<Omes.Model.Page> pages = db.GetAllPages();
        //    // get first node page
        //    List<Omes.Model.Page> firstpages = pages.Where(p => (p.ParentId == 1)).ToList();
        //    // add to treeview control
        //    foreach (Page firstpage in firstpages)
        //    {
        //        Omes.Model.Page temp = firstpage;
        //        TreeNode fristnode = new TreeNode(temp.PageName, temp.Id.ToString(), "",
        //                                          "/ContentMangeAddChildMenu.aspx?nodeid=" + temp.Id, "");
        //        //get fristnode childnode
        //        List<Omes.Model.Page> childpages = pages.Where(p => (p.ParentId == temp.Id)).ToList();
        //        //add to first node
        //        foreach (Page childpage in childpages)
        //        {
        //            fristnode.ChildNodes.Add(new TreeNode(childpage.PageName, childpage.Id.ToString(), "", "/ContentManageChildMenuEdit.aspx?nodeid=" + childpage.Id, ""));
        //        }
        //        BarMenu.Nodes.Add(fristnode);
        //        BarMenu.CollapseAll();
        //        BarMenu.ShowLines = true;
        //        BarMenu.NodeStyle.NodeSpacing = 10;
        //        BarMenu.NodeStyle.HorizontalPadding = 5;
        //        BarMenu.SelectedNodeStyle.BackColor = System.Drawing.Color.DarkGray;
        //    }
        //}

        public List<Omes.Model.PageType> GetPageTypes(int id)
        {
            List<Omes.Model.PageType> result = new List<PageType>();
            DbServer bd = new DbServer();
            result = bd.GetPageTypes(id);
            return result;
        }

        public Omes.Model.Page GetPage(int id)
        {
            Omes.Model.Page result = new Omes.Model.Page();
            DbServer db = new DbServer();
            result = db.GetPage(id);
            if (result == null)
            {
                result = new Omes.Model.Page() { PageName = "" };
            }
            return result;
        }

        public Omes.Model.PageType GetPageType(int id)
        {
            PageType type = new PageType();
            DbServer db = new DbServer();
            type = db.GetPageType(id);
            return type;
        }
    }
}